<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>hana喵喵服创造投影上传=w=</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
    <header>
        <h2>hana喵喵服创造投影上传页=w=</h2>
    </header>
    <main>
        <div class="contentbox">
            <?php
            $allowedExts = array("schem"); // 允许上传的后缀
            $temp = explode(".", $_FILES["file"]["name"]);
            $extension = end($temp);     // 获取文件后缀名
            $store_dir = "/home/ubuntu/mcserver1.20.1/plugins/FastAsyncWorldEdit/schematics/"; //上传保存路径
            $msg = "";

            if (in_array($extension, $allowedExts)) {
                if ($_FILES["file"]["error"] > 0) {
                    $msg = "错误：文件过大！请限制在8MB以内！";
                } else {
                    //echo "上传文件名: " . $_FILES["file"]["name"] . "<br>";
                    //echo "文件类型: " . $_FILES["file"]["type"] . "<br>";
                    //echo "文件大小: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
                    //echo "文件临时存储的位置: " . $_FILES["file"]["tmp_name"] . "<br>";

                    // 判断当期目录下的 upload 目录是否存在该文件
                    // 如果没有 upload 目录，你需要创建它，upload 目录权限为 777
                    if (file_exists($store_dir . $_FILES["file"]["name"])) {
                        $msg = $_FILES["file"]["name"] . " 文件已经存在！";
                    } else {
                        // 如果 upload 目录不存在该文件则将文件上传到 upload 目录下
                        move_uploaded_file($_FILES["file"]["tmp_name"], $store_dir . $_FILES["file"]["name"]);
                        //echo "文件存储在: " . $store_dir . $_FILES["file"]["name"];
                        $msg = "上传成功！";
                    }
                }
            } else {
                $msg = "非法的文件格式, 请先转换为.schem格式";
            }

            echo "<p>" . $msg . "</p>";

            ?>
            <div class="next"><a href="schem_upload.html">返回</a></div>
        </div>
    </main>
    <footer>
        schematica uploader © powered by HanazonoSerenya
    </footer>
</body>

</html>